package com.dong.module.user.controller;

import com.dong.common.annotation.RequestMapping;
import com.dong.common.pojo.ResultVO;
import com.dong.module.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import java.util.Map;

/**
 * @description:
 * @author: 陈瑞东
 * @create: 2021-08-25 11:14
 */
@Controller
@RequestMapping("user")
public class UserController{

    @Autowired
    private UserService userService;

    @RequestMapping("configParams")
    public ResultVO<Map<String,String>> configParams() {
        Map<String,String> data = userService.configParams();
        return ResultVO.success(data);
    }

    @RequestMapping("login")
    public ResultVO<Void> login(String username, String password) {
        try {
            userService.login(username, password);
        } catch (Exception e) {
            return ResultVO.fail(e.getMessage());
        }
        return ResultVO.success(null);
    }

    @RequestMapping("reg")
    public ResultVO<Void> reg(String username, String nickname, String password) {
        try {
            userService.reg(username, nickname, password);
        } catch (Exception e) {
            return ResultVO.fail(e.getMessage());
        }
        return ResultVO.success(null);
    }
}
